package com.cqfae.deploycentral.app.web.controller;

/**
 * Created by YANGHENG940 on 2017/7/12.
 */

import com.cqfae.deploycentral.app.utils.GsonUtils;
import com.cqfae.deploycentral.app.services.CommonControllerService;
import com.cqfae.deploycentral.app.services.ReportRequireService;
import com.cqfae.deploycentral.app.utils.NullUtil;
import com.cqfae.deploycentral.app.web.request.ReportRequireRequest;
import com.cqfae.deploycentral.app.web.response.WebResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>测试需求controller</p>
 *
 * @author yangheng@cmhk.com
 * @since 1.0.0-snapshot
 */
@RestController
@RequestMapping("/deploy-central/report/require")
public class ReportRequireController implements CommonControllerService<Object> {

    private static Logger logger = LoggerFactory.getLogger(ReportRequireController.class);

    @Autowired
    private ReportRequireService reportRequireService;

    @RequestMapping(value = "/info")
    public WebResponse pageInfo(ReportRequireRequest request) {
        logger.info("==== pageInfo ReportRequireRequest :==== {}", GsonUtils.getInstance().toJson(request));
        return getWebResponse(reportRequireService.page(request));
    }

    @RequestMapping(value = "/delete")
    public WebResponse delete(@RequestBody ReportRequireRequest request) {
        Assert.isTrue(NullUtil.isNotEmpty(request) && request.getId()>0,"非法测试报告需求Id");
        logger.info("==== delete ReportRequireRequest :==== {}",  GsonUtils.getInstance().toJson(request));
        return getWebResponse(reportRequireService.deleteOne(request.getId()));
    }

    @Override
    public WebResponse getWebResponse(Object obj) {
        WebResponse webResponse = new WebResponse();
        if (NullUtil.isNotEmpty(obj)) {
            webResponse.setData(obj);
        }
        return webResponse;
    }
}
